package engine.newUi
{
	import engine.control.loading.MultLoader;
	import engine.data.BindManage;
	import engine.data.ModelLocator;
	import engine.data.ObjectData;
	import engine.data.ResPath;
	import engine.data.RoleVo;
	import engine.data.View;
	import engine.data.ViewObject;
	import engine.display.newAttack.action.effect.PointPlayLite;
	import engine.flag.ResourcesPath;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.scene.player.MoveAction;
	import engine.tip.TipsMainLogic;
	import engine.tip.tipItem.MarrowItem;
	import engine.ui.MsgTipsLogic;
	import engine.util.FilterUtil;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.system.ApplicationDomain;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	import newx.com.ResManager;
	import newx.com.config.StaticIni;
	import newx.com.control.NxClip;
	import newx.com.control.button.NxButton;
	import newx.com.control.window.NxWindowEvent;

	/**
	 *洗髓实际操作界面 
	 * @author yanghr
	 * 
	 */
	public class DoMarrowLogic
	{
		private static var _self:DoMarrowLogic;
		private const PROPERT_HEAD:String="Item_";
		private const INDEX:String="index";
		private const PROPERT_NAME:String="propertyName";
		private const ISLOCK:String="isLock";
		private const COIN:int=2;
		private const SAVVY:int=1;
		private const CONDITION:String="condition";
		private const TIPS:String="tips";
		private const SOURCE:String="sourece";
		private const NUM:String="numberrrr";
		private const QUALITY:String="quality";
		private const BTN:String="btnn";
		private const MAX:String="max";
		private const LEVELMAX:String = "levelmax";
		/**
		 *数字保留位数 
		 */		
		private const PRECECIAL:int=2;
		private const RED:String="FF0000",YELLOW:String="e5cc80";
		/**
		 *品质 
		 */		
		public const GREEN:int=0,BLUE:int=1,PURPLE:int=2,
				QUALITY_ARR:Array=["1eff00","1eff00","1eff00","20BFF8","20BFF8","20BFF8","a335ee","a335ee","a335ee","ffff00","ffff00","ffff00","e5cc80","e5cc80","e5cc80"];
		/**
		 * 
		 */		
		private const LIFE:int=0, 
						NORMAL_ATT:int=1,
						SKILL_ATT:int=2,
						VOLT:int=3,
						DODGE:int=4
						;
		/**
		 *洗髓最高等级 
		 */		
		private const MAX_MAR_LEVEL:int = 11;
		private const MAXLEN:int=3;
		private var _currentLvl:int;
		private var _savvyCount:int;
		private var _magicCoin:int;
		private var _currPropertyMap:Object={};
		private var _partnerLevel:int;
		private var _sendName:String;
		private var _upeffectbol:Boolean;
		
		public static function getInstance():DoMarrowLogic
		{
			if(_self==null)
			{
				_self=new DoMarrowLogic();
			}
			return _self;
		}
		public function get ui():DoMarrowUI
		{
			if(!_ui)
				_ui	=	new DoMarrowUI;
			return _ui;
		}
		private var _bind:BindManage;
		private var _model:ModelLocator;
		private var _role:RoleVo;
		private var _tip:TipsMainLogic;
		private var _ui:DoMarrowUI;
		
		private var _bindRec:int=-1;
		private var _bindCountRec:int=-1;
		private var _bindSavvyFlag:int=-1;
		private var _bindMagicFlag:int = -1;
		
		private var _isInit:Boolean=false;
		private var _islockbelow:Boolean;
		private var _configid:int;
		private var _config:Object;
		private var _currentZoneVecMap:Object={};
		private var _serverMap:Object={};
		private var _serverArr:Array=[];
		private var _serverPointMap:Object={};
		private var _pos:int;
		
		private var _effectFlame:Array = [4,6,2,5,1,3];
		private var _effect:MovieClip;
		
		public var created:Boolean;
		private var _saveObj:Object;
		private var _tipObj:Object;
		private var _zeroBol:Boolean;
		private var _clickMc:MovieClip;

		public function set pos(value:int):void
		{
			if(!_serverArr[value])
				_serverArr[value]=_serverMap={};
			else
				_serverMap=_serverArr[value];
			_pos = value;
		}

		public function  Init():void
		{
			_bind=BindManage.getInstance();
			_model=ModelLocator.getInstance();
			_role=_model.scene.Role;
			_tip=TipsMainLogic.instance;
			const PRE_:String="_";
			var len:int=ui.mainGroup.row;
			var mc:MovieClip;
			var btn:NxButton;
			for (var i:int = 0; i < len	; i++) 
			{
				mc	=	ui.mainGroup.getItemByIndex(i);
				for(var j:int = 1; j <= 7; j++){
					mc["txt_" + j].mouseEnabled=false;
				}
//				mc["txt7"].visible=false;
//				mc["txt7"].wordWrap=false;
//				mc["txt7"].autoSize=TextFieldAutoSize.LEFT;
//				mc["txt6"].htmlText=StaticIni.getSwfLangStr("RandomPropertyTips_7")//"洗髓";
//				mc["txt2"].htmlText=StaticIni.getSwfLangStr("RandomPropertyTips_8")//"RandomPropertyTips_8=锁定下限;
//				mc["txt5"].htmlText=StaticIni.getSwfLangStr("AlertEx_1");//取消
				var nx:NxClip=new NxClip;
				mc[SOURCE]=nx
				mc["icon"].addChild(nx);
				mc[INDEX]=i;
				mc[ISLOCK]=function (val:*):Boolean
				{
					if(val is Boolean)
					{
						this[PRE_+ISLOCK]=val;
						this[CONDITION]();
					}
					if(int(val)==-1)
					{
						this[PRE_+ISLOCK]=!this[PRE_+ISLOCK];
						this[CONDITION]();
					}
					this["lockBtn"].gotoAndStop(this[PRE_+ISLOCK]?2:1);
					return this[PRE_+ISLOCK];
				}
				mc[COIN]=function(num:int=-1):int
				{
//					trace("DoMarrowLogic.COIN(num)",num);
					if(num>0)
					{
						this[PRE_+COIN]=num;
						this[CONDITION]();
					}
					return 	mc[PRE_+COIN];
				}
				mc[SAVVY]=function(num:int=-1):int
				{
//					trace("DoMarrowLogic.SAVVY(num)",num);
					if(num>0)
					{
						this[PRE_+SAVVY]=num;
						this[CONDITION]();
					}
					return this[PRE_+SAVVY]
				}
				mc[CONDITION]=function ():void
				{
					if(this[MAX])
					{
						this[TIPS]=StaticIni.getSwfLangStr("RandomPropertyTips_20");
						this[BTN](false);
						return ;
					}
					var s:int=this[PRE_+CONDITION]();
					var b:Boolean=this[ISLOCK](null);
					var savvyStr:String=this[PRE_+SAVVY];
					var coinStr:String=this[PRE_+COIN];
//					trace("DoMarrowLogic.CONDITION()",s);
					if(s)
					{
//						this[BTN](false);
						if(s&SAVVY)
						{
							savvyStr=_tip.getColorHtml(savvyStr,RED);
						}
						 if(s&COIN)
						{
							coinStr=_tip.getColorHtml(coinStr,RED);
						}
					}
					else
					{
//						this[BTN](true);
						
					}
					if(b)
					{
						this[TIPS]=StaticIni.getSwfLangStrVar("RandomPropertyTips_13",[savvyStr,coinStr]);
					}else
					{
						this[TIPS]=StaticIni.getSwfLangStrVar("RandomPropertyTips_12",[savvyStr]);
					}
				}
				mc[BTN]=function (b:Boolean):void
				{
					if(b)
					{
						this["btn"].enabled=true;
						(this["btn"] as DisplayObject).filters=null;
					}
					else
					{
						this["btn"].enabled=false;
						(this["btn"] as DisplayObject).filters=[FilterUtil.GrayColorFilter]
					}
				}
				mc[PRE_+CONDITION]=function ():int
				{
					var result:int=0;
					if(savvyCount<this[PRE_+SAVVY])
					{
						result|=SAVVY;
					}
					if(_role.getMagicCoin()<this[PRE_+COIN]	&&	this[PRE_+ISLOCK])
					{
						result|=COIN
					}
					return result;
				}
				mc[ISLOCK](false);
				mc.addEventListener(MouseEvent.MOUSE_MOVE,itemRollOver)
				mc.addEventListener(MouseEvent.MOUSE_OUT,_tip.hide);
//				_tip.objRollshowTips(mc["lockBtn"],lockTips)
//				_tip.objRollshowTips(mc["txt2"],lockTips)
			}
			_model.addEventListener(CustomToClientFlag.SERVER_CUSTOMMSG_WASH_PLUP_VALUE+"",makeSureHandle);
//			_model.addEventListener(CustomToClientFlag.SERVER_CUSTOMMSG_WASH_ADD_POINT+"",sureExchangeHandle);
			//属性请求
			_model.addEventListener(CustomToClientFlag.SERVER_CUSTOMMSG_WASH_PROPNAME_AND_VALUE+"",getExchangeObj);
		}
		private function itemRollOver(e:Event):void
		{
			var mc:MovieClip=e.currentTarget as MovieClip;
			var stri:String="";
			if(mc["lockBtn"].contains(e.target as DisplayObject)|| e.target==mc["txt_2"])
			{
				if(mc[LEVELMAX]){
					stri = StaticIni.getSwfLangStr("RandomPropertyTips_31");
				} else {
					stri = StaticIni.getSwfLangStr("RandomPropertyTips_14");//RandomPropertyTips_14=消耗元宝锁定当前属性下限值
				}
			}
			if(e.target==mc["btn"])
			{
				stri=mc[TIPS];
//				RandomPropertyTips_12=需要消耗{@0:数值}悟性
//				RandomPropertyTips_13=需要消耗{@0:数值}悟性，{@1:数值}元宝
			}
			if(e.target == mc["txt_7"] || e.target == mc["loadingLine"] || e.target == mc["loadingLineBack"]){
				if(mc[LEVELMAX]){
					stri = StaticIni.getSwfLangStr("RandomPropertyTips_30");
				} else {
					stri = StaticIni.getSwfLangStr("RandomPropertyTips_26");
				}
			}
			_tip.showMain(stri);
		}
//		private function sureExchangeHandle(e:CustomMsgEvent):void
//		{
//			const CONST_ARR:Array=["","蓝色","紫点"]
//			var pos:int=e.pList.shift();
//			var propertName:String=e.pList[0];
//			var costFlag:int=e.pList[1];
////			SitAlerLogic.getIntatic().setUIinfo("你确定要用于一个"+CONST_ARR[costFlag]+" 来加"+StaticIni.getSwfLangStr(PROPERT_HEAD+propertName)+"属性吗",null,sendExchange,getQualifiedClassName(this)+CustomToClientFlag.SERVER_CUSTOMMSG_WASH_ADD_POINT);
//		}
		private function sendExchange():void
		{
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_ENABLE_ADD_PLUP);
		}
		
		private function makeSureHandle(e:CustomMsgEvent):void
		{
			var pos:int=e.pList.shift();
			var num:Number=e.pList[0];
			var propertyN:String=e.pList[1];
			var index:int=_currPropertyMap[propertyN]
//			setInfoByProperties(index,propertyN,num);
//			setUpOrDownState(index,num,true)
			changeState(index,0);
			for (var i:int = 0; i < MAXLEN; i++) 
			{
				if(i==index)
					continue;
				ui.mainGroup.getItemByIndex(i)[BTN](false);
			}
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_ENABLE_WASH_PLUP);
//			var num:Number=obj[propertyN];
//			var propertName:String=StaticIni.getSwfLangStrVar(PROPERT_HEAD+e.pList[1],[getNumStr(num)]);
//			var current:Number=_currPropertyMap[e.pList[1]]
//			SitAlerLogic.getIntatic().setUIinfo("新值:"+propertName+",你确定要改变？",null,sendSure,getQualifiedClassName(this)+CustomToClientFlag.SERVER_CUSTOMMSG_WASH_PLUP_VALUE);
		}
		
		private function setInfoByProperties(index:int,propName:String,number:Number):void
		{
			var num:Number=number;
			var propertyN:String=propName
			var	pZone:Point;
			var quality:int=-1;
			var str:String;
			//			var num:Number=obj[propertyN];
			var o:Object=findQualityPoint(_currentLvl,propertyN,num);
			pZone=o[1];
			quality=o[0];
			var stt:String=StaticIni.getSwfLangStrVar(PROPERT_HEAD+propertyN,[getNumStr(num)]);
			stt=stt==PROPERT_HEAD+propertyN	?	propertyN	:	stt;
			if(MarrowItem.checkInt(propertyN))
				str	=	"("+pZone.x+" - "+pZone.y+")";
			else
				str	=	"("+pZone.x+"% - "+pZone.y+"%)";
			var realNum:Number=ui.mainGroup.getItemByIndex(index)[NUM]
//			setUpOrDownState(index,num-realNum,true);
			setInfoByIndex(index,_tip.getColorHtml(stt,QUALITY_ARR[quality])).setZoneByIndex(index,str)
		}
		private function getNumStr(num:Number):String
		{
			return DetailPropertyLogic.getInstance().outZero(num.toFixed(PRECECIAL))
		}
		private function sendSure():void
		{
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_ENABLE_WASH_PLUP);
		}
		private function cancel(index:int):void
		{
			var mc:MovieClip=ui.mainGroup.getItemByIndex(index);
			setInfoByProperties(index,mc[PROPERT_NAME],mc[NUM]);
			setUpOrDownState(index,0,false);
			changeState(index,1);
			savvyRefresh();
		}
		/**
		 *重设传送队列 
		 * 
		 */		
		public function resetTansmit():void
		{
			_callingserverMap={}
		}
		public function	AfterHide():void
		{
			removeAllEventListener()
			resetTansmit()
			if(_effect){
				ui.effectBg.removeChild(_effect);
				_effect = null;
			}
			created = false;
		}
		public function addAllEventListener():void
		{
			ui.mainGroup.addItemsEvent(MouseEvent.CLICK,actorItemClick);
			ui.windowBG.addEventListener(NxWindowEvent.WINDOW_CLOSE,close);
//			_bindRec	=	(_bindRec	==	-1&&_pos==-1)	?	_bind.BindRecord(_model.scene,"WashPulpBaseRec",addRecHandle,removeRecHandle):_bindRec;
		}
		public function bindAll():void
		{
			if(_bindSavvyFlag==-1)
			{
				_bindSavvyFlag	=	_bind.BindProp(_role,"Savvy",this,"savvyCount");
			}
			if(_bindMagicFlag == -1){
				_bindMagicFlag = _bind.BindProp(_role, "MagicCoin", this, "magicCoin");
			}
//			_bindCountRec	=	_bindCountRec_	==	-1	?	_bind.BindRecord(_model.scene,"WashPointValueRec",addPointHandle,removePointHandle):_bindCountRec;
		}
		
		/**
		 *元宝  
		 * @return 
		 * 
		 */		
		public function get magicCoin():int
		{
			return _magicCoin;
		}
		
		public function set magicCoin(value:int):void
		{
			_magicCoin = value;
			if(ui.created){
				savvyRefresh();
			}
		}
		/**
		 *悟性值 
		 * @return 
		 * 
		 */		
		public function get savvyCount():int 
		{
			return _savvyCount; 
		}
		public function set savvyCount(value:int):void
		{
			_savvyCount=value;
//			ui.blueLab.htmlStr=StaticIni.getSwfLangStrVar("RandomPropertyTips_9",[value]);
			ui.knowLab.htmlText = String(value);
			if(ui.created){
				savvyRefresh();
			}
		}
		
		private function savvyRefresh():void
		{
			for (var i:int = 0; i < MAXLEN; i++) 
			{
				ui.mainGroup.getItemByIndex(i)[CONDITION]();
				if(_clickMc && _clickMc["index"] == i){
					_clickMc = ui.mainGroup.getItemByIndex(i);
				}
				setBtnSatuesIndex(ui.mainGroup.getItemByIndex(i));
			}
			//如果tips在显示中，则刷新
			if(_tip.isMainShow){
				_tip.hide();
				var str:String = _clickMc[TIPS];
				_tip.showMain(str);
			}
			
		}
		private function addPointHandle(PropertiesName:String,PropertiesValue:Array,data:*):void
		{
			var obj:Object	=	_serverPointMap[PropertiesValue[0]];
			if(!obj)
			{
				obj=_serverPointMap[PropertiesValue[0]]	=	{};
			}
			obj[BLUE]=PropertiesValue[1];
			obj[PURPLE]=PropertiesValue[2];
			if(!_isInit) refreshPoint();
		}
		private function removePointHandle(PropertiesName:String,PropertiesValue:Array,data:*):void
		{
			var obj:Object= _serverPointMap[PropertiesValue[0]];
			if(!obj)
			{
				return ;
			}
			else
			{
				delete _serverPointMap[PropertiesValue[0]];
			}
		}
		private function addRecHandle(lvl:String,PropertiesValue:Array,data:*):void
		{
			var obj:Object	=	_serverMap[lvl];
			if(!obj)
			{
				obj=_serverMap[lvl]	=	{};
				obj[INDEX]=[];
			}
			obj[PropertiesValue[1]] = [];
			obj[INDEX].push(PropertiesValue[1]);
			obj[PropertiesValue[1]].push(PropertiesValue[2]);
			obj[PropertiesValue[1]].push(PropertiesValue[3]);
//			if(!_isInit&&ui.created)	refreshProperties();
		}
		/**
		 * 洗髓主属性
		 *serverArr[pos][lvl]//[configid]
		 * @return 
		 * 
		 */		
		public function get serverArr():Array
		{
			return _serverArr
		}
		private function removeRecHandle(PropertiesName:String,PropertiesValue:Array,data:*):void
		{
			var obj:Object= _serverMap[PropertiesValue[0]];
			if(!obj)
			{
				return ;
			}
			else
			{
				delete obj[PropertiesValue[1]];
			}
		}
		private function actorItemClick(e:Event):void
		{
			var mc:MovieClip=e.currentTarget as MovieClip;
			_clickMc = mc;
			var name:String=mc[PROPERT_NAME];
			if(e.target is SimpleButton		&&	e.target.enabled)
			{
				switch(e.target.name)
				{
					case "btn":
					{
						if(mc[ISLOCK](null))
						{
							_sendName = name;
							SitAlerLogic.getIntatic().setUIinfo(StaticIni.getSwfLangStr("RandomPropertyTips_28"), [], goldWash, mc["btn"]);
//							goldWash(name)
						}
						else
						{
							_sendName = name;
							SitAlerLogic.getIntatic().setUIinfo(StaticIni.getSwfLangStr("RandomPropertyTips_28"), [], savvyWash, mc["btn"]);
//							savvyWash(name)
						}
						break
					}
//					case "btn1":
//					{
//						sendSure()
//						break;	
//					}
//					case "btn2":
//					{
//						cancel(mc[INDEX])
//						break;
//					}
				}
			
			}
			else
			{
				if(mc["lockBtn"].contains(e.target as DisplayObject))
				{
					mc[ISLOCK](-1);
					setBtnSatuesIndex(mc);
				}
			}
		}
		/**
		 *声望洗髓 
		 * @param propert
		 * 
		 */		
		private function savvyWash():void
		{
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_WASH_PLUP,_currentLvl,_sendName,0,_pos);
		}
		/**
		 *元宝洗髓 
		 * @param propert
		 * 
		 */		
		private function goldWash():void
		{
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_WASH_PLUP,_currentLvl,_sendName,1,_pos);
		}
		/**
		 *洗点 
		 * @param propert
		 * 已废弃
		 */		
		private function washPoint(propert:String):void
		{
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_WASH_POINT,_currentLvl,(propert),_pos)
		}
		/**
		 *加点 
		 * @param propert
		 * 已废弃
		 */		
		private function addPoint(propert:String):void
		{
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_ADD_POINT,_currentLvl,(propert),_pos)			
		}
		/**
		 * 
		 * @param configid 配置id
		 * @param lvl	洗髓等级
		 * @param pos	位置objkey主角为-1
		 * 
		 */		
		public function callForShow(configid:int,lvl:int,pos:int,level:int):void
		{
//			trace("DoMarrowLogic.callForShow(configid, lvl)",configid,lvl);
			_isInit=true;
			this.pos	=	pos;
			_partnerLevel = level;
			this.configid	=	configid;
			_currentLvl	=	lvl;
			bindAll()
			currentLvl	=	_currentLvl;
//			if(_pos==-1)
//			{
//				_ui.showOrHide();
//			}
//			else
//			{
//				requestForServerobj(_currentLvl,pos);
//			}
			if(!created){
				_ui.show();
				created = true;
			}
			_saveObj = new Object;
			_tipObj = new Object;
			_clickMc = null;
			refreshProperties();
			addAllEventListener();
			bindAll();
			_isInit=false;
		}
		
		/**
		 *检查  当前位置的属性是否是view的属性 
		 * @param view
		 * @param pos
		 * @return 
		 * 
		 */		
		public function checkServerObj(view:ObjectData,pos:int):Boolean
		{
			var serverobj:Object=serverArr[pos];
//			!arr[pos]||!arr[pos].hasOwnProperty(lvl)||
			if(!serverobj||!serverobj.hasOwnProperty(_role.GetPropertiesEx("WLYBCurFloor"))||(serverobj["configid"]!=-1&&view is RoleVo)||(view is ViewObject&&serverobj["configid"]!=view.GetPropertiesEx("ConfigID")	))
			{
//				trace("DoMarrowLogic.checkServerObj(view, pos)",view);
				return false;
			}
			return true;
		}
		private var _callingserverMap:Object={};
		/**
		 *请求服务器数据 
		 * @param currentLvl
		 * @param pos
		 * 
		 */		
		public function requestForServerobj(currentLvl:int,pos:int):void
		{
			if(_callingserverMap.hasOwnProperty(currentLvl)	&&	_callingserverMap[currentLvl]==pos)
				return ;
			_callingserverMap[currentLvl]=pos;
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_WASH_VALUE,currentLvl,pos);
		}
		/**
		 *@private
		 * 删除请求服务器数据 
		 * @param lvl
		 * @param pos
		 * 
		 */		
		public function deleteProperty(lvl:int,pos:int):void
		{
			if(_callingserverMap[lvl]==pos)
			{
				delete _callingserverMap[lvl];
			}
		}
		private function getExchangeObj(e:CustomMsgEvent):void
		{
//			trace("DoMarrowLogic.getExchangeObj(e)",e.pList);
			var arr:Array=e.pList.concat();
			pos=arr.shift();
			var configID:int	=	_pos==-1?-1:(_model.scene.GetView(View.VIEWPORT_PARTNER).GetPropertiesEx(_pos+"") as ViewObject).GetPropertiesEx("ConfigID");
			var lvl:String=arr.shift();
			var num:int=arr.shift();
			var tempArr:Array=[];
			var washLogic:WashMarrowLogic=WashMarrowLogic.getInstance();
			_serverMap["configid"]=configID;
			for (var i:int = 0; i < num; i++) 
			{
				tempArr[0]=_currentLvl;
				tempArr[1]=arr[i*3];
				tempArr[2]=arr[i*3+1];
				tempArr[3]=arr[i*3+2];
				addRecHandle(lvl,tempArr,null);
			}
			deleteProperty(int(lvl),_pos);
//			_serverArr[pos]=_serverMap
//			refreshPoint()
//			refreshProperties();
//			if (!_ui.created)
//			{
//				addAllEventListener()
//				_ui.showOrHide();
//			}
			if(ui.created	&&	int(lvl)==_currentLvl	&&_configid	==	washLogic.currentSeletedRole.GetPropertiesEx("ConfigID"))
			{
				refreshProperties()
			}
		}
		private function refreshPoint():void
		{
			if(_serverPointMap.hasOwnProperty(_currentLvl))
			{
				blueCount=_serverPointMap[_currentLvl][BLUE];
				purpleCunt=_serverPointMap[_currentLvl][PURPLE];
			}
			else
			{
				blueCount=0;
				purpleCunt=0;
			}
		}
		/**
		 *洗髓等级 
		 * @param index
		 * @param num
		 * @return 
		 * 
		 */		
		private function setQuaByIndex(index:int,num:int):DoMarrowLogic
		{
//			ui.mainGroup.getItemByIndex(index)["txt3"].htmlText=_tip.getColorHtml(StaticIni.getSwfLangStrVar("UIString_1000036",[num]),YELLOW);
			if(_upeffectbol){
				var mc:MovieClip = new MovieClip;
				mc = ResManager.newResClass("mcxisui_007") as MovieClip;
				mc.x = 52;
				mc.y = 61;
//				var sprite:MovieClip = ui.mainGroup.getItemByIndex(index)["icon"] as MovieClip;
				ui.mainGroup.getItemByIndex(index).addChild(mc);
				_upeffectbol = false;
//				new PointPlayLite( sprite, new Point(0,0), mc );
				mc.addFrameScript(mc.totalFrames -1,
					function ():void{
						mc.stop();
						ui.mainGroup.getItemByIndex(index).removeChild(mc);
						mc = null;
					});
			}
			ui.mainGroup.getItemByIndex(index)["txt_5"].htmlText = _tip.getColorHtml(num + "/" + MAX_MAR_LEVEL, YELLOW);
			return this;
		}
		/**
		 *洗髓图片
		 * @param index
		 * @param property
		 * @return 
		 * 
		 */		
		private function setPicByIndex(index:int,property:String):DoMarrowLogic
		{
			ui.mainGroup.getItemByIndex(index)[SOURCE].source = ResPath.JPG+StaticIni.getIniObj("PropertyPic")[property]+".jpg";
			ui.mainGroup.getItemByIndex(index)[SOURCE].width = 45;
			ui.mainGroup.getItemByIndex(index)[SOURCE].height = 45;
			return this
		}
		/**
		 *洗髓范围 
		 * @param index
		 * @param source
		 * @return 
		 * 
		 */		
		private function setZoneByIndex(index:int,source:String):DoMarrowLogic
		{
			ui.mainGroup.getItemByIndex(index)["txt_3"].htmlText=source;
			return this;
		}
		/**
		 *洗髓属性 
		 * @param index
		 * @param source
		 * @return 
		 * 
		 */		
		private function setInfoByIndex(index:int,source:String):DoMarrowLogic
		{
			ui.mainGroup.getItemByIndex(index)["txt_1"].wordWrap=false;
			ui.mainGroup.getItemByIndex(index)["txt_1"].autoSize=TextFieldAutoSize.LEFT;
			ui.mainGroup.getItemByIndex(index)["txt_1"].htmlText=source;
			return this;
		}
		
		/**
		 *洗髓剩余经验 
		 * @param index
		 * @param source
		 * @return 
		 * 
		 */		
		private function setLeftExpIndex(index:int, source:String):DoMarrowLogic
		{
			ui.mainGroup.getItemByIndex(index)["txt_4"].htmlText = source;
			if(source == StaticIni.getSwfLangStr("RandomPropertyTips_27")){
				ui.mainGroup.getItemByIndex(index)["btn"].visible = false;
				ui.mainGroup.getItemByIndex(index)["lockBtn"].visible = false;
				ui.mainGroup.getItemByIndex(index)["txt_2"].visible = false;
				ui.mainGroup.getItemByIndex(index)["txt_6"].visible = false;
			} else {
				ui.mainGroup.getItemByIndex(index)["btn"].visible = true;
				ui.mainGroup.getItemByIndex(index)["lockBtn"].visible = true;
				ui.mainGroup.getItemByIndex(index)["txt_2"].visible = true;
				ui.mainGroup.getItemByIndex(index)["txt_6"].visible = true;
			}
			return this;
		}
		
		/**
		 *洗髓幸运值 
		 * @param index
		 * @param source
		 * @return 
		 * 
		 */		
		private function setLukyIndex(index:int, source:String, level:int):DoMarrowLogic
		{
			var obj:Object = StaticIni.getIniObj("LuckyCount");
			var _all:int = obj[level];
			var per:String = (int(source) / _all).toFixed(2);
			var perc:int = int(Number(per) * 100) > 100 ? 100 : int(Number(per) * 100);
			ui.mainGroup.getItemByIndex(index)["txt_7"].htmlText = level > (MAX_MAR_LEVEL - 1) ? "0%" : perc + "%";
			ui.mainGroup.getItemByIndex(index)["loadingLine"].width = level > (MAX_MAR_LEVEL - 1) ? 0 : 113 * (int(source) / _all);
			return this;
		}
		
		/**
		 *设定洗髓按钮状态 
		 * @param index
		 * @return 
		 * 
		 */		
		private function setBtnSatuesIndex(mc:DisplayObjectContainer):void
		{
			if(mc[ISLOCK](null)){
				if(mc[COIN](-1) > magicCoin || mc[SAVVY](-1) > savvyCount){
					mc["btn"].enabled = false;
					(mc["btn"] as DisplayObject).filters = [FilterUtil.GrayColorFilter];
				} else {
					mc["btn"].enabled = true;
					(mc["btn"] as DisplayObject).filters = [];
				}
			} else {
				if(mc[SAVVY](-1) > savvyCount){
					mc["btn"].enabled = false;
					(mc["btn"] as DisplayObject).filters = [FilterUtil.GrayColorFilter];
				} else {
					mc["btn"].enabled = true;
					(mc["btn"] as DisplayObject).filters = [];
				}
			}
//			return this;
		}
		
		private function changeState(index:int,state:int):void
		{
			var mc:MovieClip	=	ui.mainGroup.getItemByIndex(index);
//			if(state)
//			{
//				mc["txt4"].visible=false;
//				mc["txt5"].visible=false;
//				mc["btn2"].visible=false;
//				mc["btn1"].visible=false;
//				
//				mc["txt6"].visible=true;
//				mc["btn3"].visible=true;
//			}
//			else
//			{
//				mc["txt4"].visible=true;
//				mc["txt5"].visible=true;
//				mc["btn2"].visible=true;
//				mc["btn1"].visible=true;
//				
//				mc["txt6"].visible=false;
//				mc["btn3"].visible=false;
//			}
		}
		/**
		 * 
		 * @param index
		 * @param b  true:上 ;false:下
		 * 已废弃
		 */		
		private function setUpOrDownState(index:int,b:Number,bool:Boolean):DoMarrowLogic
		{
			var mc:MovieClip=ui.mainGroup.getItemByIndex(index)
			var t:TextField=mc["txt7"];
			var propertyN:String=mc[PROPERT_NAME];
			var precent:Object=StaticIni.getIniObj("PercentMap");
			b=b-mc[NUM];
			var bS:String=DetailPropertyLogic.getInstance().outZero(b.toFixed(2));
			t.visible=bool;
			if(precent.hasOwnProperty(propertyN))
				t.htmlText=b>0?("+"+bS+"%"):_tip.getColorHtml((bS+"%"),RED);
			else
				t.htmlText=b>0?("+"+bS):_tip.getColorHtml((bS+""),RED);
//			t.gotoAndStop((b));
			return this
		}
		/**
		 *在lvl等级下的属性 Properties  的数字是num
		 * 返回所在区间Object【1】和品质Object【0】 
		 * @param lvl
		 * @param Properties
		 * @param num
		 * @return 
		 * 
		 */		
		public function findQualityPoint(lvl:int,Properties:String,num:Number):Object
		{
			var proMap:Object;
			var vec:Vector.<Point>;
			var str:String	=	StaticIni.getIniObj("PropertyRank"+lvl)[Properties];
			var arr2:Array
			var	pZone:Point;
			var color:int
			var quality:int=-1;
			if(_currentZoneVecMap.hasOwnProperty(lvl))
			{
				proMap=_currentZoneVecMap[lvl]
				if(proMap.hasOwnProperty(Properties))
				{
					vec=_currentZoneVecMap[lvl][Properties];
					for each (var i:Point in vec) 
					{
						if(isInZone(num,i))
						{
							pZone=isInZone(num,i)
							quality=vec.indexOf(i);
							break
						}
					}
					if(!pZone)
					{
						pZone=vec[vec.length-1];
						quality=vec.indexOf(pZone);;
					}
					color=(num==pZone.y&&quality==(MAX_MAR_LEVEL - 1))?quality+1:quality
					return {0:quality,1:pZone,2:color}; 
				}
				
			}
			else
			{
				_currentZoneVecMap[lvl]=proMap={}//new Vector.<Point>
			}
				vec=proMap[Properties]=new Vector.<Point>;
				arr2=str.split(";")[0].split(",");
				for (var j:int = 0; j < arr2.length-1; j++) 
				{
					vec[j]=new Point(arr2[j],arr2[j+1]);
					if(isInZone(num,vec[j]))
					{
						pZone=isInZone(num,vec[j]);
						quality=j;
					}
				}
				if(quality==-1)
				{
					quality=vec.length-1
					pZone=vec[quality];
				}
				color=(num==pZone.y&&quality==(MAX_MAR_LEVEL - 1))?quality+1:quality
				return {0:quality,1:pZone,2:color}; 
			
		}
		private function refreshProperties():void
		{
			var obj:Object=_serverMap[_currentLvl];
			if(!obj)return ;
			var arr:Array=obj[INDEX];
			var color:int;
			_currPropertyMap={};
			for (var i:int = 0; i < Math.min(arr.length,MAXLEN); i++) 
			{
				var propertyN:String=arr[i];
				if(obj.hasOwnProperty(propertyN))
				{
					var num:Number=obj[propertyN][0];
					var	pZone:Point;
					var quality:int;
					var str:String;
					var leftExpStr:String;
					var lukyStr:String = obj[propertyN][1];
					var o:Object=findQualityPoint(_currentLvl,propertyN,num);
					pZone=o[1];
					//判断是否播放升级特效
					if(!_saveObj[propertyN]){
						_saveObj[propertyN] = [];
					} else {
						for(var j:String in _saveObj){
							if(propertyN == j){
								if(num > _saveObj[propertyN]){
									_upeffectbol = true;
								} else {
									_upeffectbol = false;
								}
							}
						}
					}
					//判断是否播放洗髓失败提示
					if(!_tipObj[propertyN]){
						_tipObj[propertyN] = [];
					} else {
						for(j in _tipObj){
							if(propertyN == j){
								if((num - _tipObj[propertyN]) == 0){
									_zeroBol = true;
								} else {
									_zeroBol = false;
								}
							}
						}
					}
					_saveObj[propertyN] = pZone.y;
					_tipObj[propertyN] = num;
					quality=o[0];
					color=o[2]
					_currPropertyMap[propertyN]=i;
					var stt:String=StaticIni.getSwfLangStrVar(PROPERT_HEAD+propertyN,[getNumStr(num)]);
					stt=stt==PROPERT_HEAD+propertyN	?	propertyN	:	stt;
					var precent:Object=StaticIni.getIniObj("PercentMap");
					if(precent.hasOwnProperty(propertyN)){
						//				str	=	"("+pZone.x+" - "+pZone.y+")";
						str	=	StaticIni.getSwfLangStrVar("RandomPropertyTips_22", [pZone.x, pZone.y]);
						leftExpStr = StaticIni.getSwfLangStrVar("RandomPropertyTips_25", [(pZone.y - num).toFixed(2)]);
					}
					else{
						//				str	=	"("+pZone.x+"% - "+pZone.y+"%)";
						str	=	StaticIni.getSwfLangStrVar("RandomPropertyTips_23", [pZone.x, pZone.y]);
						leftExpStr = StaticIni.getSwfLangStrVar("RandomPropertyTips_24", [(pZone.y - num)]);
					}
					 var mc:MovieClip= ui.mainGroup.getItemByIndex(i);
					 mc[BTN](true);
					mc[PROPERT_NAME]=propertyN;
					mc[NUM]=num;
					mc[QUALITY]=quality;
					
					mc[MAX]=(quality==(MAX_MAR_LEVEL - 1)&&num==pZone.y);
					mc[LEVELMAX] = (quality == (MAX_MAR_LEVEL - 1));
					str			= mc[MAX] ? StaticIni.getSwfLangStr("RandomPropertyTips_20") : str;
//					leftExpStr = quality==(MAX_MAR_LEVEL - 1) ? StaticIni.getSwfLangStr("RandomPropertyTips_27") : leftExpStr;
					leftExpStr = mc[MAX] ? StaticIni.getSwfLangStr("RandomPropertyTips_27") : leftExpStr;
					
					//属性值不变
					if(_zeroBol && _clickMc && _clickMc["propertyName"] == propertyN){
						var _tipMsg:MsgTipsLogic = MsgTipsLogic.getRes(_clickMc, -130, 60);
						_tipMsg.showInfo(StaticIni.getSwfLangStr("RandomPropertyTips_29"));
					}
					
					if(mc[MAX])
					{
						mc[CONDITION]();
					}
					
					changeState(i,1)
					setInfoByIndex(i,_tip.getColorHtml(stt,QUALITY_ARR[color])).setPicByIndex(i,propertyN)
						.setQuaByIndex(i,quality+1)./*setUpOrDownState(i,0,false).*/setZoneByIndex(i,str)
						.setLeftExpIndex(i, leftExpStr).setLukyIndex(i, lukyStr, quality+1).setCost(mc,quality);
					setBtnSatuesIndex(mc);
//					setPicByIndex(i,num.toFixed(1));
				}
			}
		}
		private function setCost(mc:MovieClip,quality:int):void
		{
//			trace("DoMarrowLogic.setCost(mc, quality)",mc[INDEX]);
			var ssA:Array=(StaticIni.getIniObj("Expend")[_currentLvl]+"").split(";"); 
//			var isLock:Boolean=mc[ISLOCK](null);
			if(quality < MAX_MAR_LEVEL)//			if(isLock)
			{
				mc[SAVVY](ssA[0].split(",")[quality]);
				mc[COIN](ssA[1].split(",")[quality]);
//				stri=StaticIni.getSwfLangStrVar("RandomPropertyTips_13",[ssA[0].split(",")[stri],ssA[1].split(",")[stri]]);
			}
			else
			{
				mc[SAVVY](0);
				mc[COIN](0);
//				stri=StaticIni.getSwfLangStrVar("RandomPropertyTips_12",[ssA[0].split(",")[stri]]);
			}
			
		}
		private function isInZone(numb:Number,zone:Point):Point
		{
			if( numb>=zone.x	&&	numb<zone.y)
			{
				return zone;	
			}
			return null;
		}
		public function set currentLvl(value:int):void 
		{
			_currentLvl=value;
			_config=StaticIni.getIniObj("PropertyRank"+_currentLvl);
			//
			ui.effectBg.gotoAndStop(_effectFlame[value - 1]);
			
			if(_effect){
				ui.effectBg.removeChild(_effect);
				_effect = null;
			}
			_effect = new MovieClip;
			if(value == 5){
				value = 6;
			} else if (value == 6){
				value = 5;
			}
			_effect = ResManager.newResClass("mcxisui_00" + value) as MovieClip;
			_effect.x = 39;
			_effect.y = 43;
			ui.effectBg.addChild(_effect);
//			MultLoader.getInstance().deletAllSource();
			
		}
		public function set purpleCunt(value:int):void 
		{
//			_ui.purpleLab.htmlStr="UIString_1000633"+value;
		}
		public function set blueCount(value:int):void 
		{
//			_ui.blueLab.htmlStr="UIString_1000634"+value;
		}
		public function set configid(value:int):void
		{
			_configid=value;
			var name:String;
			var level:int;
			var modelID:int;
			var clothModel:int;
			var obj:Object = StaticIni.getIniObj(String(_configid));
			name = _configid == 0 ? _role.getPlayerName() : obj["name"];
			level = _configid == 0 ? _role.getPlayerLevel() : _partnerLevel;
			modelID = _configid == 0 ? _role.ModelId : obj["Model"];
			clothModel = _configid == 0 ? _role.clotheModel : 0;
			
			_ui.nameLab.htmlText=_tip.getColorHtml(value?StaticIni.getSwfLangStr(value+""):name,"ffff00")
			_ui.levelLab.htmlText = String(level);
			_ui.rolePic.source = ResourcesPath.getHeadPic(modelID, clothModel);
		}
		public function removeAllEventListener():void
		{
			if(_bindSavvyFlag!=-1)
			{
				_bindSavvyFlag	=	_bind.UnbindProp(_role,"SavvyValue",_bindSavvyFlag)
			}
			if(_bindMagicFlag != -1){
				_bindMagicFlag = _bind.UnbindProp(_role, "MagicCoin", _bindMagicFlag);
			}
			ui.mainGroup.removeItemsEvent(MouseEvent.CLICK,actorItemClick);			
		}
		private function close(e:Event):void
		{
			_ui.showOrHide();
			if(_effect){
				ui.effectBg.removeChild(_effect);
				_effect = null;
			}
			created = false;
		}
	}
}